import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

//路由懒加载
// const login = () => import('./views/login.vue');
// const home = () => import('../views/Home.vue');
// const notFound = () => import('../views/error/404.vue')

const routes = [
    {
        path: "/",
        redirect: "/Expert"
    },
    {
        path: "/Home",
        name: "Home",
        component: () => import('../views/Home.vue')
    },
    {
        path: "/Activate",
        name: "Activate",
        component: () => import('../views/Activate.vue')
    },
        {
            path: "/Expert",
            name: "Expert",
            redirect: "/Expert/ExpertSearchBox",
            component: () => import('../views/Expert/Expert.vue'),
            children: [{
                path: "ExpertSearchBox",
                name: "ExpertSearchBox",
                component: () => import('../views/Expert/ExpertSearchBox.vue')
            }, {
                path: "Info",
                name: "ExpertInfo",
                component: () => import('../views/Expert/ExpertInfo.vue')
            }]
        },
        {
            path: "/Team",
            name: "Team",
            redirect: "/Team/TeamSearchBox",
            component: () => import('../views/Team/Team.vue'),
            children: [{
                path: "TeamSearchBox",
                name: "TeamSearchBox",
                component: () => import('../views/Team/TeamSearchBox.vue')
            }, {
                path: "Info",
                name: "TeamInfo",
                component: () => import('../views/Team/TeamInfo.vue')
            }]
        },
       {
            path: "/UserCenter",
            name: "UserCenter",
            redirect: "/UserCenter/Preselect/Expert",
            component: () => import('../views/UserCenter/UserCenter.vue'),
            children: [{
                path: "Preselect/:type",
                name: "Preselect",
                component:  () => import('../views/UserCenter/Preselect.vue')
            }, {
                path: "Favorite/:type",
                name: "Favorite",
                component: () => import('../views/UserCenter/Favorite.vue')
            }, {
                path: "Setting",
                name: "Setting",
                component:  () => import('../views/UserCenter/Setting.vue')
            }, {
                path: "DownloadCenter",
                name: "DownloadCenter",
                component:  () => import('../views/UserCenter/DownloadCenter.vue')
            }]
        },
         {
            path: "/Admin",
            name: "Admin",
            component: () => import('../views/Admin/Admin.vue'),
            children: [{
                path: "index",
                name: "Index",
                component: () => import('../views/Admin/Admin.vue')
            }, {
                path: "UserManage",
                name: "UserManage",
                component: () => import('../views/Admin/User/UserManage.vue')
            }, {
                path: "ExpertInfoManage",
                name: "ExpertInfoManage",
                component: () => import('../views/Admin/Expert/ExpertInfoManage.vue')
            }, {
                path: "EditExpertInfo",
                name: "EditExpertInfo",
                component: () => import('../views/Expert/ExpertInfo.vue'),
                props: !0
            }, {
                path: "ExpertCategoryManage",
                name: "ExpertCategoryManage",
                component: () => import('../views/Admin/Expert/ExpertCategoryManage.vue')
            }, {
                path: "ExpertDirectionManage",
                name: "ExpertDirectionManage",
                component: () => import('../views/Admin/Expert/ExpertDirectionManage.vue')
            }, {
                path: "ExpertDomainManage",
                name: "ExpertDomainManage",
                component: () => import('../views/Admin/Expert/ExpertDomainManage.vue')
            }, {
                path: "TeamInfoManage",
                name: "TeamInfoManage",
                component: () => import('../views/Admin/Team/TeamInfoManage.vue')
            }, {
                path: "TeamDirectionManage",
                name: "TeamDirectionManage",
                component: () => import('../views/Admin/Team/TeamDirectionManage.vue')
            }, {
                path: "TeamDomainManage",
                name: "TeamDomainManage",
                component: () => import('../views/Admin/Team/TeamDomainManage.vue')
            }, {
                path: "SystemBasicData",
                name: "SystemBasicData",
                component: () => import('../views/Admin/Statistics/SystemBasicData.vue')
            }, {
                path: "UseDetailsData",
                name: "UseDetailsData",
                component: () => import('../views/Admin/Statistics/UseDetailsData.vue')
            }, {
                path: "StorageDetailsData",
                name: "StorageDetailsData",
                component: () => import('../views/Admin/Statistics/StorageDetailsData.vue')
            }]
        }]

const vueRouter = new Router({
    mode: 'hash',
    routes: routes
})
// 路由拦截器
/*vueRouter.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
    }
    const whiteList = ['/login', '/autuoLogin']// 不重定向白名单
    const accessToken = sessionStorage.getItem('token') // 获取浏览器缓存的用户信息
    if (localStorage.userInfo) {
        if (to.path === '/login') {
            next({path: '/'})
        }
        if (to.path === '/404' || to.path === '/' || to.path === '/login') {
            next('/login')
        } else {
            next()
        }
    } else {
        if (whiteList.indexOf(to.path) !== -1) {
            next()
        } else {
            next('/login')
        }
    }
})*/
vueRouter.beforeEach((to, from, next) => {
    vueRouter.app.$cookies.isKey("user") || to.path.startsWith("/Home") || to.path.startsWith("/Activate") ? next() : next({
        path: "/Home"
    })
})
export default vueRouter
